package autopilot {	
	import flash.display.MovieClip;	
	import flash.events.TimerEvent;	
	import flash.net.SharedObject;	
	import flash.text.TextField;	
	import flash.utils.Timer;	
	
	import com.googlecode.milib.abstract.IMLBroadcastClassListener;	
	import com.googlecode.milib.abstract.MLBroadcastClass;	
	import com.googlecode.milib.display.button.views.ButtonViewFourFrames;	
	import com.googlecode.milib.display.service.MLButton;	
	import com.googlecode.milib.vo.MLEventInfo;	
	
	/**
	 * @author Marek Brun 'minim'
	 */
	public class Startpanel extends MLBroadcastClass implements IMLBroadcastClassListener {
		
		//DATA:	{
		//			u:Number,		//			login:String		//			pass:String
		//		}
		public const event_Start : Object = {name:'Start'};
		
		public var mc:MovieClip;
		private var mc_btnStart : MovieClip;
		private var mc_tfUNum : TextField;
		private var btnStart:MLButton;		
		private var cookie:SharedObject;		
		private var mc_tfPass:TextField;		
		private var mc_tfLogin:TextField;				private var autoLoginTimer:Timer;
				public function Startpanel(mc:MovieClip) {
			this.mc=mc;
			mc_btnStart=MovieClip(mc.getChildByName('btnStart'));
			
			mc_tfUNum=TextField(mc.getChildByName('tfUNum'));			mc_tfUNum.restrict='0-9';
			mc_tfPass=TextField(mc.getChildByName('tfPass'));			mc_tfLogin=TextField(mc.getChildByName('tfLogin'));
			
			btnStart=MLButton.forInstance(mc_btnStart);
			btnStart.addListener(this);
			btnStart.addButtonView(ButtonViewFourFrames.forInstance(mc_btnStart));
			cookie=SharedObject.getLocal('startPanel');			autoLoginTimer=new Timer(1000*60, 1);			autoLoginTimer.addEventListener(TimerEvent.TIMER, onAutoLoginTimer);
			if(cookie.data.pass) {
				mc_tfUNum.text=cookie.data.u;				mc_tfPass.text=cookie.data.pass;				mc_tfLogin.text=cookie.data.login;				autoLoginTimer.start();
			}					}//<>				protected function login():void {			autoLoginTimer.stop();			broadcastEvent(event_Start, {login:mc_tfLogin.text, pass:mc_tfPass.text, u:Number(mc_tfUNum.text)});		}//<<
		
//********************************************************************************************
//		events for Startpanel
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case btnStart:
					switch(ev.event) {
						case btnStart.event_Press:
							if(mc_tfUNum.text.length>0 && mc_tfLogin.text.length>0 && mc_tfPass.text.length>0){
								cookie.data.u=mc_tfUNum.text;
								cookie.data.login=mc_tfLogin.text;								cookie.data.pass=mc_tfPass.text;
								cookie.flush();								login();
							}
						break;
					}
				break;
			}
		}//<<				protected function onAutoLoginTimer(event:TimerEvent):void {			login();		}//<<
		
	}
}
